package com.wangjie.prefixsum;

/**
 * @author jieshao
 * @date 2022/3/23 11:07
 *
 * 303. 区域和检索 - 数组不可变
 */
public class Test01 {
    public static void main(String[] args) {
        int[] arr = {-2, 0, 3, -5, 2, -1};

        PrefixSumBase prefixSumBase = new PrefixSumBase(arr);
        int result1 = prefixSumBase.sumRange(0, 2);
        int result2 = prefixSumBase.sumRange(2, 5);
        int result3 = prefixSumBase.sumRange(0, 5);

        System.out.println("------------方式1------------");
        System.out.println("result1 = " + result1);
        System.out.println("result2 = " + result2);
        System.out.println("result3 = " + result3);

        PrefixSum prefixSum = new PrefixSum(arr);
        int result4 = prefixSum.query(0, 2);
        int result5 = prefixSum.query(2, 5);
        int result6 = prefixSum.query(0, 5);

        System.out.println("------------方式2------------");
        System.out.println("result4 = " + result4);
        System.out.println("result5 = " + result5);
        System.out.println("result6 = " + result6);
    }
}